//
//  MSTabBarView.m
//  MSCustomTabBarController
//
//  Created by MrSong on 16/6/7.
//  Copyright © 2016年 MrSong. All rights reserved.
//

#import "MakeAppointmentController.h"
#import "CKPuslichTool.h"
#import "HandleNetProduct.h"
#import "NeedPersionalController.h"
#import "RegularViewController.h"
#import "MyNavigationController.h"
#import "MSTabBarView.h"
#import "NeedPersionalController.h"
#import "UserModel.h"

@interface MSTabBarView ()

@property (nonatomic, strong) IBOutletCollection(UIView) NSArray *items;

@property (nonatomic, assign) NSInteger selectIndex;

@end

@implementation MSTabBarView

#pragma mark - Life Cycle

- (void)awakeFromNib
{
    [super awakeFromNib];
    UIViewSetRadius(_numLabel, 9, 0, nil);
    if ([[[NSUserDefaults standardUserDefaults] objectForKey:@"ReminderNew"] isEqualToString:@"YES"]) {
        self.picNew.hidden = YES;
    }else{
        self.picNew.hidden = NO;
    }
    self.selectIndex = 0;
}

#pragma mark - Actions

- (IBAction)selectItem:(UIButton *)sender
{
    // button的tag对应tabBarController的selectedIndex
    // 设置选中button的样式
    self.selectIndex = sender.tag;
    // 让代理来处理切换viewController的操作
//    if ([self.viewDelegate respondsToSelector:@selector(msTabBarView:didSelectItemAtIndex:)]) {
//        [self.viewDelegate msTabBarView:self didSelectItemAtIndex:sender.tag];
//    }
}

- (void)setNumberText:(NSString *)num
{
    if ([num intValue] == 0) {
        self.numLabel.hidden = YES;
    }else{
        self.numLabel.hidden = NO;
        self.numLabel.text = num;
    }
}

#pragma mark - Setter

- (void)setSelectIndex:(NSInteger)selectIndex
{
    switch (selectIndex) {
        case 0:
        {
            
            [[NSNotificationCenter defaultCenter] postNotificationName:@"RELOADHOMELIST" object:nil];
        }
            break;
        case 1:
        {
            
            
            
//            if ([[UserModel getUser].Accountstatus intValue]==2) {
//                [HandleNetProduct getUserIDConfirmStatusForAccountPhone:[UserModel getUser].Phone Success:^(NSDictionary *data) {
//                    if ([data[@"IDConfirm"] isEqualToString:@"完成"] && [data[@"InvestorConfirm"] isEqualToString:@"完成"]) {
//                        //实名认证合格投资者认证ok
//                        
//                        //判断临时客户，去预约理财师
//                        MakeAppointmentController *Login = (MakeAppointmentController *)[CKPuslichTool getViewControllerFromStroyBoard:@"Product" viewID:@"MakeAppointmentController"];
//                        [((MyNavigationController *)self.tabVc.selectedViewController) pushViewController:Login animated:YES];
//                        return;
//                    }
//                } Failure:^(NSString *errorInfo) {
//                    
//                }];
//                
//                
//            }
            [[NSNotificationCenter defaultCenter] postNotificationName:@"RELOADMYLIST" object:nil];
        }
            break;
        case 2:
        {
            
           
        }
            break;
        case 3:
        {
            _picNew.hidden = YES;
            [[NSUserDefaults standardUserDefaults] setObject:@"YES" forKey:@"ReminderNew"];
            
        }
            break;
        case 4:
        {
            
            
        }
            break;
            
        default:
            break;
    }
   
    // 先把上次选择的item设置为可用
    UIButton *lastItem = _items[_selectIndex];
    lastItem.enabled = YES;
    // 再把这次选择的item设置为不可用
    UIButton *item = _items[selectIndex];
    item.enabled = NO;
    _selectIndex = selectIndex;
    self.tabVc.selectedIndex = _selectIndex;
}

@end
